#include "lolevel.h"
#include "platform.h"
#include "core.h"

static long *nrflag = (long*)0x6E50;

#include "../../../generic/capt_seq.c"

void __attribute__((naked,noinline)) sub_FF9A2ABC_my(long p)
{
    asm volatile (
                "STMFD   SP!, {R4,LR}\n"
                "MOV     R4, R0\n"
                "SUB     SP, SP, #0xC\n"
                "BL      sub_FF9A3514\n"
                "MVN     R1, #0\n"
                "BL      sub_FF820E7C\n"
                "MOV     R0, #0x120\n"
                "ADD     R0, R0, #2\n"
                "ADD     R1, SP, #4\n"
                "MOV     R2, #4\n"
                "BL      sub_FF8258D4\n"
                "TST     R0, #1\n"
                "BEQ     loc_FF9A2AFC\n"
                "LDR     R0, =0xFF9A2938\n"
                "MOV     R1, #0x1DC\n"
                "BL      sub_FF813D70\n"
"loc_FF9A2AFC:\n"
                "LDR     R3, =0xA4840\n"
                "LDR     R2, =0xA4900\n"
                "LDR     R0, [R3,#0x84]\n"
                "LDRSH   R1, [R2,#0xE]\n"
            //  "BL      nullsub_32\n"
                "MOV     R0, R4\n"
                "BL      sub_FF9A28BC\n"
                "BL      wait_until_remote_button_is_released\n"
                "BL      capt_seq_hook_set_nr\n" // +
                "LDR     R3, =0x6E54\n"
                "LDR     R0, [R3]\n"
                "B       sub_FF9A2B20\n"
    );
}

void __attribute__((naked,noinline)) sub_FF99ECBC_my(long p)
{
    asm volatile (
                "STMFD   SP!, {R4,R5,LR}\n"
                "LDR     R3, =0xA4840\n"
                "LDR     R4, [R0,#0xC]\n"
                "LDR     R1, [R3,#0x28]\n"
                "LDR     R2, [R4,#8]\n"
                "CMP     R1, #0\n"
                "ORR     R2, R2, #1\n"
                "STR     R2, [R4,#8]\n"
                "BNE     loc_FF99ED10\n"
                "MOV     R0, #0xC\n"
                "BL      sub_FF9AA050\n"
                "TST     R0, #1\n"
                "BEQ     loc_FF99ED10\n"
                "LDR     R3, [R4,#8]\n"
                "MOV     R0, #1\n"
                "ORR     R3, R3, #0x40000000\n"
                "STR     R3, [R4,#8]\n"
"loc_FF99ED00:\n"
                "MOV     R2, R4\n"
                "MOV     R1, #1\n"
                "LDMFD   SP!, {R4,R5,LR}\n"
                "B       sub_FF99D184\n"
"loc_FF99ED10:\n"
                "LDR     R1, =0xA4840\n"
                "MOV     R3, #0x8200\n"
                "LDRH    R2, [R1]\n"
                "ADD     R3, R3, #0xA\n"
                "CMP     R2, R3\n"
                "BEQ     loc_FF99ED5C\n"
                "LDRH    R3, [R1,#0x90]\n"
                "CMP     R3, #3\n"
                "BEQ     loc_FF99ED5C\n"
                "LDR     R3, [R4,#0xC]\n"
                "CMP     R3, #1\n"
                "BLS     loc_FF99ED5C\n"
                "LDRH    R3, [R1,#0x8E]\n"
                "CMP     R3, #0\n"
                "BNE     loc_FF99ED5C\n"
                "LDRH    R3, [R1,#0x8A]\n"
                "CMP     R3, #2\n"
                "BNE     loc_FF99ED5C\n"
                "BL      sub_FF99FF74\n"
"loc_FF99ED5C:\n"
                "LDR     R1, =0xA4840\n"
                "MOV     R3, #0x8200\n"
                "LDRH    R2, [R1]\n"
                "ADD     R3, R3, #0xA\n"
                "CMP     R2, R3\n"
                "BEQ     loc_FF99EDA4\n"
                "LDRH    R3, [R1,#0x90]\n"
                "CMP     R3, #3\n"
                "BEQ     loc_FF99EDA4\n"
                "LDR     R3, [R4,#0xC]\n"
                "CMP     R3, #1\n"
                "BLS     loc_FF99EDA4\n"
                "LDRH    R3, [R1,#0x8E]\n"
                "CMP     R3, #0\n"
                "BNE     loc_FF99EDA4\n"
                "LDRH    R3, [R1,#0x8A]\n"
                "CMP     R3, #2\n"
                "BEQ     loc_FF99EE0C\n"
"loc_FF99EDA4:\n"
                "LDR     R2, =0xA4840\n"
                "LDRH    R3, [R2,#0x90]\n"
                "CMP     R3, #3\n"
                "BEQ     loc_FF99EE24\n"
                "LDRH    R3, [R2,#0x8E]\n"
                "CMP     R3, #0\n"
                "BNE     loc_FF99EE24\n"
                "LDRH    R1, [R2,#0x8A]\n"
                "CMP     R1, #1\n"
                "BNE     loc_FF99EE24\n"
                "LDRH    R2, [R2]\n"
                "MOV     R3, #0x8200\n"
                "ADD     R3, R3, #0xA\n"
                "CMP     R2, R3\n"
                "BEQ     loc_FF99EE24\n"
                "LDR     R3, [R4,#0xC]\n"
                "CMP     R3, #1\n"
                "BLS     loc_FF99EE24\n"
                "ADD     R3, R1, #0xFF00\n"
                "ADD     R3, R3, #0xFF\n"
                "MOV     R3, R3,LSL#16\n"
                "CMP     R3, #0x10000\n"
                "BHI     loc_FF99EE24\n"
                "LDR     R3, [R4,#0x10]\n"
                "CMP     R3, #1\n"
                "BNE     loc_FF99EE24\n"
"loc_FF99EE0C:\n"
                "LDR     R3, =0x77BB4\n"
                "MOV     R2, #0xEA00\n"
                "LDR     R0, [R3]\n"
                "MOV     R1, #0x8000000\n"
                "ADD     R2, R2, #0x60\n"
                "BL      sub_FF9AA4D4\n"
"loc_FF99EE24:\n"
                "LDR     R5, =0xA4840\n"
                "BL      sub_FF99EB9C\n"
                "LDR     R3, [R5,#0x28]\n"
                "CMP     R3, #0\n"
                "BNE     loc_FF99EE40\n"
                "MOV     R0, #2\n"
                "BL      sub_FFB41A74\n"
"loc_FF99EE40:\n"
                "BL      sub_FF99FA40\n"
                "LDR     R3, [R5,#0x28]\n"
                "CMP     R3, #0\n"
                "BNE     loc_FF99EE8C\n"
                "MOV     R0, R4\n"
                "BL      sub_FF9A24F4\n"
                "MOV     R0, R4\n"
                "BL      sub_FF9A0DA0\n"
                "TST     R0, #1\n"
                "BNE     loc_FF99ED00\n"
                "BL      sub_FF9E6F24\n"
                "BL      sub_FF825AD0\n"
                "STR     R0, [R4,#0x14]\n"
                "MOV     R0, R4\n"
                "BL      sub_FF9A29A4\n"
                "BL      sub_FF9A33A0\n"
                "MOV     R0, R4\n"
                "BL      sub_FF9A2ABC_my\n"         //------------->
                "BL      capt_seq_hook_raw_here\n"  // +
                "B       loc_FF99EEA0\n"
"loc_FF99EE8C:\n"
                "LDR     R3, =0x6E20\n"
                "LDR     R2, [R3]\n"
                "CMP     R2, #0\n"
                "MOVNE   R0, #0x1D\n"
                "MOVEQ   R0, #0\n"
"loc_FF99EEA0:\n"
                "MOV     R1, #1\n"
                "MOV     R2, R4\n"
                "BL      sub_FF99D184\n"
                "BL      sub_FF9A2E90\n"
                "CMP     R0, #0\n"
                "LDRNE   R3, [R4,#8]\n"
                "ORRNE   R3, R3, #0x2000\n"
                "STRNE   R3, [R4,#8]\n"
                "LDR     R2, =0xA4840\n"
                "LDRH    R3, [R2,#0x90]\n"
                "CMP     R3, #3\n"
                "LDMEQFD SP!, {R4,R5,PC}\n"
                "LDRH    R3, [R2,#0x8E]\n"
                "CMP     R3, #0\n"
                "LDMNEFD SP!, {R4,R5,PC}\n"
                "LDRH    R3, [R2,#0x8A]\n"
                "CMP     R3, #2\n"
                "LDMNEFD SP!, {R4,R5,PC}\n"
                "MOV     R0, R4\n"
                "LDMFD   SP!, {R4,R5,LR}\n"
                "B       sub_FF99FFCC\n"
    );
}

void __attribute__((naked,noinline)) sub_FF99EF00_my(){
  asm volatile (
                "STMFD   SP!, {R4,LR}\n"
                "BL      sub_FF99E6A8\n"
                "LDR     R3, =0xA4840\n"
                "LDR     R2, [R3,#0x28]\n"
                "CMP     R2, #0\n"
                "MOV     R4, R0\n"
                "MOV     R0, #0xC\n"
                "BEQ     loc_FF99EF48\n"
                "BL      sub_FF9AA050\n"
                "TST     R0, #1\n"
                "BEQ     loc_FF99EF48\n"
                "LDR     R3, [R4,#8]\n"
                "LDR     R2, =0x6E20\n"
                "ORR     R3, R3, #0x40000000\n"
                "MOV     R1, #1\n"
                "STR     R1, [R2]\n"
                "STR     R3, [R4,#8]\n"
                "LDMFD   SP!, {R4,PC}\n"
"loc_FF99EF48:\n"
                "MOV     R0, R4\n"
                "BL      sub_FF9A24F4\n"
                "BL      sub_FF9E6F24\n"
                "BL      sub_FF825AD0\n"
                "STR     R0, [R4,#0x14]\n"
                "MOV     R0, R4\n"
                "BL      sub_FF9A2ABC_my\n"         //-------->
                "BL      capt_seq_hook_raw_here\n"  // +
                "TST     R0, #1\n"
                "LDRNE   R3, =0x6E20\n"
                "MOVNE   R2, #1\n"
                "STRNE   R2, [R3]\n"
                "LDMFD   SP!, {R4,PC}\n"
  );
}


void __attribute__((naked,noinline)) capt_seq_task()
{
  asm volatile (
                "STMFD   SP!, {R4,R5,LR}\n"
                "SUB     SP, SP, #4\n"
                "MOV     R5, SP\n"
                "B       loc_FF99F52C\n"
"loc_FF99F344:\n"
                "LDR     R2, [SP]\n"
                "LDR     R3, [R2]\n"
                "MOV     R0, R2\n"
                "CMP     R3, #0x19\n"
                "LDRLS   PC, [PC,R3,LSL#2]\n"
                "B       loc_FF99F500\n"
                ".long loc_FF99F3C4\n"
                ".long loc_FF99F3E4\n"
                ".long loc_FF99F3F8\n"
                ".long loc_FF99F40C\n"
                ".long loc_FF99F404\n"
                ".long loc_FF99F414\n"
                ".long loc_FF99F41C\n"
                ".long loc_FF99F428\n"
                ".long loc_FF99F430\n"
                ".long loc_FF99F43C\n"
                ".long loc_FF99F444\n"
                ".long loc_FF99F44C\n"
                ".long loc_FF99F454\n"
                ".long loc_FF99F45C\n"
                ".long loc_FF99F464\n"
                ".long loc_FF99F470\n"
                ".long loc_FF99F478\n"
                ".long loc_FF99F480\n"
                ".long loc_FF99F488\n"
                ".long loc_FF99F494\n"
                ".long loc_FF99F4A0\n"
                ".long loc_FF99F4A8\n"
                ".long loc_FF99F4E8\n"
                ".long loc_FF99F4F0\n"
                ".long loc_FF99F4F8\n"
                ".long loc_FF99F514\n"
"loc_FF99F3C4:\n"
                "BL      sub_FF99FA68\n"
                "BL      shooting_expo_param_override\n"  // +
                "BL      sub_FF99CBE4\n"
                "LDR     R3, =0xA4840\n"
                "LDR     R2, [R3,#0x28]\n"
                "CMP     R2, #0\n"
                "BEQ     loc_FF99F510\n"
                "BL      sub_FF99EF00_my\n" //------------->
                "B       loc_FF99F510\n"
"loc_FF99F3E4:\n"
                "BL      sub_FF99ECBC_my\n" //------------->
"loc_FF99F3E8:\n"
                "LDR     R2, =0xA4840\n"
                "MOV     R3, #0\n"
                "STR     R3, [R2,#0x28]\n"
                "B       loc_FF99F510\n"
"loc_FF99F3F8:\n"
                "MOV     R0, #1\n"
                "BL      sub_FF99FD28\n"
                "B       loc_FF99F510\n"
"loc_FF99F404:\n"
                "BL      sub_FF99F628\n"
                "B       loc_FF99F3E8\n"
"loc_FF99F40C:\n"
                "BL      sub_FF99FA20\n"
                "B       loc_FF99F3E8\n"
"loc_FF99F414:\n"
                "BL      sub_FF99FA30\n"
                "B       loc_FF99F510\n"
"loc_FF99F41C:\n"
                "BL      sub_FF99FBC8\n"
                "BL      sub_FF99CBE4\n"
                "B       loc_FF99F510\n"
"loc_FF99F428:\n"
                "BL      sub_FF99EFE4\n"
                "B       loc_FF99F510\n"
"loc_FF99F430:\n"
                "BL      sub_FF99FC7C\n"
                "BL      sub_FF99CBE4\n"
                "B       loc_FF99F510\n"
"loc_FF99F43C:\n"
                "BL      sub_FF99FA20\n"
                "B       loc_FF99F510\n"
"loc_FF99F444:\n"
                "BL      sub_FF9A1674\n"
                "B       loc_FF99F510\n"
"loc_FF99F44C:\n"
                "BL      sub_FF9A18B8\n"
                "B       loc_FF99F510\n"
"loc_FF99F454:\n"
                "BL      sub_FF9A1970\n"
                "B       loc_FF99F510\n"
"loc_FF99F45C:\n"
                "BL      sub_FF9A1A0C\n"
                "B       loc_FF99F510\n"
"loc_FF99F464:\n"
                "MOV     R0, #0\n"
                "BL      sub_FF9A1E94\n"
                "B       loc_FF99F510\n"
"loc_FF99F470:\n"
                "BL      sub_FF9A20A0\n"
                "B       loc_FF99F510\n"
"loc_FF99F478:\n"
                "BL      sub_FF9A2138\n"
                "B       loc_FF99F510\n"
"loc_FF99F480:\n"
                "BL      sub_FF9A21F4\n"
                "B       loc_FF99F510\n"
"loc_FF99F488:\n"
                "MOV     R0, #1\n"
                "BL      sub_FF9A1E94\n"
                "B       loc_FF99F510\n"
"loc_FF99F494:\n"
                "BL      sub_FF99FEFC\n"
                "BL      sub_FF99EA7C\n"
                "B       loc_FF99F510\n"
"loc_FF99F4A0:\n"
                "BL      sub_FF9A1D1C\n"
                "B       loc_FF99F510\n"
"loc_FF99F4A8:\n"
                "LDR     R4, =0xA48A0\n"
                "MOV     R0, #0x11\n"
                "MOV     R1, R4\n"
                "MOV     R2, #2\n"
                "BL      sub_FF8258D4\n"
                "TST     R0, #1\n"
                "BEQ     loc_FF99F4D4\n"
                "MOV     R1, #0x4C0\n"
                "LDR     R0, =0xFF99E7BC\n"
                "ADD     R1, R1, #6\n"
                "BL      sub_FF813D70\n"
"loc_FF99F4D4:\n"
                "LDRH    R3, [R4]\n"
                "CMP     R3, #1\n"
                "BNE     loc_FF99F510\n"
                "BL      sub_FF9A1D08\n"
                "B       loc_FF99F510\n"
"loc_FF99F4E8:\n"
                "BL      sub_FF9A1DB4\n"
                "B       loc_FF99F510\n"
"loc_FF99F4F0:\n"
                "BL      sub_FF99EB9C\n"
                "B       loc_FF99F510\n"
"loc_FF99F4F8:\n"
                "BL      sub_FF99B988\n"
                "B       loc_FF99F510\n"
"loc_FF99F500:\n"
                "MOV     R1, #0x4E0\n"
                "LDR     R0, =0xFF99E7BC\n"
                "ADD     R1, R1, #7\n"
                "BL      sub_FF813D70\n"
"loc_FF99F510:\n"
                "LDR     R2, [SP]\n"
"loc_FF99F514:\n"
                "LDR     R3, =0x77BB4\n"
                "LDR     R1, [R2,#4]\n"
                "LDR     R0, [R3]\n"
                "BL      sub_FF820CE0\n"
                "LDR     R0, [SP]\n"
                "BL      sub_FF99E8AC\n"
"loc_FF99F52C:\n"
                "LDR     R3, =0x77BB8\n"
                "MOV     R1, R5\n"
                "LDR     R0, [R3]\n"
                "MOV     R2, #0\n"
                "BL      sub_FF8213F8\n"
                "TST     R0, #1\n"
                "BEQ     loc_FF99F344\n"
                "MOV     R1, #0x410\n"
                "LDR     R0, =0xFF99E7BC\n"
                "ADD     R1, R1, #9\n"
                "BL      sub_FF813D70\n"
                "BL      sub_FF822954\n"
                "ADD     SP, SP, #4\n"
                "LDMFD   SP!, {R4,R5,PC}\n"
	);
}

